<template>
  <div class="box">
    <p>企业名称：{{companyName}}</p>
    <p>被服务人姓名：{{serveDetail.userName}}</p>
    <p>被服务人性别：{{serveDetail.sexValue}}</p>
    <p>被服务人证件类型：{{serveDetail.paperTypeValue}}</p>
    <p>被服务人证件号码：{{serveDetail.cardNum}}</p>
    <p>被服务人电话号码：{{serveDetail.mobile}}</p>
    <p>被服务人电子邮件：{{serveDetail.email || '无'}}</p>
    <p>所属商品：{{ptGoodsName}}</p>
    <p>保单号/服务单号：{{serveDetail.paper}}</p>
    <p>生效起期：{{serveDetail.beginTimeValue}}</p>
    <p>生效止期：{{serveDetail.endTimeValue}}</p>
    <p>特别约定：{{serveDetail.remark || '无'}}</p>
    <p>保单状态：{{serveDetail.statusValue}}</p>
    <div v-if="orderRelation">
        <p>关联权益人姓名：{{orderRelation.userName}}</p>
        <p>关联权益人性别：{{orderRelation.sexValue}}</p>
        <p>关联权人证件类型：{{orderRelation.paperTypeValue}}</p>
        <p>关联权益人证件号码：{{orderRelation.paper}}</p>
        <p>关联权益人电话号码：{{orderRelation.mobile}}</p>
        <p>关联权益人电子邮件：{{orderRelation.email || '无'}}</p> 
        <p>与被服务人关系：{{orderRelation.relationTypeValue}}</p>
    </div>
    <h3>修改人：{{order.operatorName}}</h3>
    <p>修改时间：{{serveDetail.updateTimeValue}}</p>
    <p>修改原因：{{serveDetail.reason}}</p>
    <!-- <p>相关附件：</p> -->
    <div>
			<el-button type="success" class="btn" @click="done(true)">同意</el-button>
			<el-button type="warning" plain class="btn" @click="done(false)">拒绝</el-button>
		</div>
  </div>

</template>

<script>
const queryString = require('querystring')
import {paperTypeList, getCompany} from 'data/listBody'
export default {
  name: 'serveInfo',
  created() {
    this.getDetail()
  },
  data() {
    return {
      serveDetail: {},
      orderRelation: {},
      order: {},
      id: this.$route.query.id,
      companyName: '',
      ptGoodsName: ''
    }
  },
  methods: {
    getDetail() {
			
			this.axios.get(`/order/${this.id}/detail`).then((res) => {
              const code = Number(res.data.code)
              if (code === 200) {
                  this.order = res.data.data
                  this.serveDetail = res.data.data.modified
                  this.getCompanyList()
                  this.getGoods()
                  this.serveDetail.paperTypeValue = this.key2Value(paperTypeList, this.serveDetail.paperType)
                  this.serveDetail.sexValue = this.serveDetail.sex == 1 ? '男' : '女'
                  this.serveDetail.beginTimeValue = this.timeFormater(this.serveDetail.beginTime).format('YYYY-MM-DD')
                  this.serveDetail.endTimeValue = this.timeFormater(this.serveDetail.endTime).format('YYYY-MM-DD')
                  this.serveDetail.updateTimeValue = this.timeFormater(this.serveDetail.updateTime).format('YYYY-MM-DD')
                  this.serveDetail.statusValue = this.getStatusValue(this.serveDetail.status)
                  this.orderRelation = res.data.data.orderRelation
                  if (this.orderRelation) {
                    this.orderRelation.sexValue = this.orderRelation.sex == 1 ? '男' : '女'
                    this.orderRelation.paperTypeValue = this.key2Value(paperTypeList, this.orderRelation.paperType)
                    this.orderRelation.relationTypeValue = this.relationCode2Value(this.orderRelation.relationType)
                  }
              } else {
                  this.$message(res.data.message)
              }
            }).catch((err) => {
              this.$message(err.message)
            })
    },
    getCompanyList() {
      this.axios.get(`/company?page=0&size=1000`).then(res => {
        if (res.data.code == 200) {
          this.companyList = res.data.data.list
          this.companyName = this.id2Name(this.companyList, this.serveDetail.companyId)
          console.log(this.companyName)
        }
      })
      .catch(err => {
        console.log(err)
      });
    },
    getGoods() {
      const params = {
        companyId: this.serveDetail.companyId,
        // page: this.currentPage - 1,
        // size: 20
      };
      this.axios
        .get('/goods?' + queryString.stringify(params))
        .then(res => {
          const code = Number(res.data.code);
          if (code === 200) {
            this.goodsList = res.data.data.list;
            console.log(this.goodsList)
            this.ptGoodsName = this.id2Name(this.goodsList, this.serveDetail.ptGoodsId)
            console.log(this.ptGoodsName)
            // this.setPage(res.data.data);
          } else {
            this.$message(this.mes.busy);
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getGoodsList() {
      this.axios.get(`/goods?page=0&size=1000`).then(res => {
        if (res.data.code == 200) {
          this.goodsList = res.data.data.list
          this.goodsName = this.id2Name(this.goodsList, this.serveDetail.goodsId)
          console.log(this.companyName)
        }
      })
      .catch(err => {
        console.log(err)
      });
    },
    relationCode2Value(code) {
      let codeList = {
            '1': '父母',
            '2': '子女',
            '3': '配偶',
            '4': '其他'
        }
      return codeList[code]
    },
		done(status) {
			const params = {
				id: this.id,
				confirm: status
			}
			this.axios.post(`/order/${this.id}/detail/confirm` , queryString.stringify(params)).then((res) => {
              const code = Number(res.data.code)
              if (code === 200) {
                  this.$message(this.mes.success)
                  this.$router.push('infoRecheck?activeName=3')
              } else {
                  this.$message(this.mes.busy)
              }
            }).catch((err) => {
              console.log(err)
              this.$message(this.mes.busy)
            })
    },
    getStatusValue(val) {
          let value = ''
          val = String(val)
          switch (val) {
            case '-1': value = '待审核'; break;
            case '0': value = '已审核'; break;
            case '-2': value = '已拒绝'; break;
          }
          return value
        }
  }
}
</script>

<style>
.box{
	padding-left: 50px
}
</style>
